package com.gzu.shop.context;

import lombok.Data;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 将每一个请求中包含的用户信息存储在threadLocal中
 * 多线程中，可以实现线程相互隔离，但需要预防内存泄漏
 */

public class BaseContext {

    public static ThreadLocal<Map<String, Object>> threadLocal = new ThreadLocal<>();

    public static Map<String, Object> getThreadLocal() {
        return threadLocal.get();
    }

    public static void setThreadLocal(Map<String, Object> map) {
        threadLocal.set(map);
    }

    public static void removeThreadLocal() {
        threadLocal.remove();
    }

}
